package com.letoken.platform.app.consumer;

import com.alibaba.fastjson.JSONObject;
import com.letoken.platform.app.util.ImHttpUtil;
import com.letoken.platform.repo.app.dto.ImUserLoginDto;
import com.letoken.platform.repo.mq.constant.ImUserConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * @author wyl
 * @date 2023/2/20 14:18
 * @Version 1.0
 */
@Slf4j
@Component
public class AppImUserConsumer {
    @RabbitListener(queues = ImUserConstant.QUEUE_IM_USER_LOGIN)
    @RabbitHandler
    public void imLogin(@Payload String message) {
        try {
            ImUserLoginDto dto = JSONObject.parseObject(message, ImUserLoginDto.class);
            ImHttpUtil.imLogin(dto);
        } catch (Exception ex) {
            log.error("MQ >> imLogin error！ [{}]", ex.getMessage());
        }
    }
}
